home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_10.lha
/
6_10
/
6_10out.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
1KB
|
66 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
*
Output a type LINT to the given stream.
/
include <lint.h>
stream& operator<< (ostream& out, LINT j)
out << form("0x%4.4x%4.4x%4.4x%4.4x, ", /* DELETE */
j.s[0], j.s[1], j.s[2], j.s[3]); /* DELETE */
LINT val = j;
// reverse sign of negative numbers
if (j.isneg())
{
val = -j;
out << "-";
}
// check for the easy single precision case
if (val.s[0] == 0 && val.s[1] == 0)
{
LINT_Ltype l = val.s[2] * LINT_base + val.s[3];
out << l;
}
else
{
// output can be stored in 5 "hyper-decimal" digits,
// each digit holding a value 0..9999.
LINT_type a[5], *p = a;
const LINT_type dec_base = 10000;
// store "digits" in reverse order
do {
// *p++ = val % 10000
// val /= 10000;
LINT_Ltype prevu = 0;
for (int r = 0; r < 4; r++)
{
LINT_Ltype tmp = val.s[r] +
prevu * LINT_base;
LINT_type tmpq = tmp / dec_base;
val.s[r] = tmpq; // % LINT_base
prevu = tmp - dec_base * tmpq;
}
*p++ = prevu;
} while (val.s[3] || val.s[2] ||
val.s[1] || val.s[0]); // val != 0
// Output digits in forward order.
// All but first digit must be 4 decimal
// digits in lengths, including leading zeros.
out << *--p;
while (--p >= a)
out << form("%4.4u", *p);
}
return out;